package com.tcm.controller.front;

import com.tcm.entity.resp.R;
import com.tcm.service.BattleService;
import com.tcm.utils.AccessTokenUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 学生对战控制器
 * @author Guqier
 * @version 1.0
 * @date 2023/9/10 14:29
 */
@RestController
@RequestMapping("/stu/battle")
@RequiredArgsConstructor
public class StuBattleController {

    private final BattleService battleService;

    /**
     * 分页获取对战记录列表
     * @param request 请求对象
     * @param page 当前页号
     * @param pageSize 页面大小
     * @return 对战记录列表
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public R getBattleList(HttpServletRequest request, @RequestParam Integer page, @RequestParam Integer pageSize){
        return R.success(battleService.getBattleList(AccessTokenUtil.getUserAccount(request), page, pageSize));
    }

    /**
     * 获取对战记录详细
     * @param battleId 对战ID
     * @param request 请求对象
     * @return 对战详细信息
     */
    @RequestMapping(value = "/detail", method = RequestMethod.GET)
    public R getBattleDetail(@RequestParam Long battleId, HttpServletRequest request){
        return R.success(battleService.getBattleDetail(battleId, AccessTokenUtil.getUserAccount(request)));
    }

}
